//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XStatic.h>
///	@path	~/src/gui/xgui/
///	@date	2008/10/30
///	@brief	.

#pragma once

#include "xeres.h"

#include "gui/IGuiControl.h"
#include "gui/style/style.h"
#include "gui/style/StyleText.h"
#include "gui/image/IBitmap.h"
#include "gui/shifter.h"

namespace xeres {

	/*! 
		\class	XLabel
		\brief	Single line label.
	*/
	class XLabel : public IGuiControl
	{
	public:

		/// \ctor
		XLabel( void );

		/// \ctor
		XLabel( const WString& label , const Rect<int>& placement );

		/// \dtor
		virtual ~XLabel( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XLabel , IGuiControl );

	public:

		/// \name Label Methods
		//@{

		/// \brief	Set label text.
		void SetText( const WString& text );

		/// \brief	Get button label.
		const WString& GetText( void ) const { return m_label.GetString(); }

		/// \brief	Get style.
		RefWeak<CTextStyle> GetStyle( void );

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	protected:

		/// \name Label Interface
		//@{

		/// \brief	Call when text is set.
		virtual void OnSetText( void );

		/// \brief	Call when set text style.
		virtual void OnSetStyle( void );

		/// \brief	Call when label is about to draw text.
		virtual void OnPreDrawText( Composition& composition , const Rect<int>& bound );

		/// \brief	Call when text is drawn.
		virtual void OnPostDrawText( Composition& composition , const Rect<int>& bound );

		//@}

	protected:

		//@ data
		StyleText			m_label;
	};

	/*! 
		\class	XTextBlock
		\brief	Text block.
	*/
	class XTextBlock : public IGuiControl
	{
	public:

		/// \ctor
		XTextBlock( void );

		/// \ctor
		XTextBlock( const WString& label , const Rect<int>& placement );

		/// \dtor
		virtual ~XTextBlock( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XTextBlock , IGuiControl );

	public:

		/// \name Label Methods
		//@{

		/// \brief	Set label text.
		void SetText( const WString& text );

		/// \brief	Get button label.
		const WString& GetText( void ) const { return m_label.GetString(); }

		/// \brief	Get style.
		RefWeak<CTextStyle> GetStyle( void );

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	protected:

		/// \name Label Interface
		//@{

		/// \brief	Call when text is set.
		virtual void OnSetText( void );

		/// \brief	Call when set text style.
		virtual void OnSetStyle( void );

		/// \brief	Call when label is about to draw text.
		virtual void OnPreDrawText( Composition& composition , const Rect<int>& bound );

		/// \brief	Call when text is drawn.
		virtual void OnPostDrawText( Composition& composition , const Rect<int>& bound );

		//@}

	protected:

		//@ data
		StyleTextBlock		m_label;
	};

	/*! 
		\class	XClickLabel
		\brief	Label that accepts click input.
	*/
	class XClickLabel : public XLabel
	{
	public:

		/// \ctor
		XClickLabel( void );

		/// \ctor
		XClickLabel( const WString& label , const Rect<int>& placement );

		/// \dtor
		virtual ~XClickLabel( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XClickLabel , XLabel );

	public:

		/// \name Label Methods
		//@{

		/// \brief	Set a click callback.
		void SetOnClick( function<void()> call );

		//@}

	protected:

		/// \name Label Interface
		//@{

		/// \brief	Call when text is set.
		virtual void OnSetText( void );

		/// \brief	Call when label is about to draw text.
		virtual void OnPreDrawText( Composition& composition , const Rect<int>& bound );

		/// \brief	Call when text is drawn.
		virtual void OnPostDrawText( Composition& composition , const Rect<int>& bound );

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when mouse enter component.
		virtual void OnMouseEnter( Updater& updater , RefWeak<IGuiComp> last );

		/// \brief	Call when mouse leave component.
		virtual void OnMouseLeave( Updater& updater , RefWeak<IGuiComp> next );

		/// \brief	Call when close window.
		virtual void OnClose( void ) { m_click = NULL; }

		//@}

		/// \name	XControl Interface
		//@{

		/// \brief	Tick update.
		virtual void Tick( Updater& updater , float dTime );

		//@}

	private:

		//@ data

		// Mouse entered animation.
		AttrShifter			m_mouseEntered;

		// callback
		function<void()>	m_click;
	};

 } // namespace xeres
